//定义cesium全局方法,cesium页面获取焦点时才能鼠标缩放，二维地图也一样。
const comjs  = {};
// comjs.dxUrl = 'https://www.supermapol.com/realspace/services/3D-stk_terrain/rest/realspace/datas/info/data/path';
comjs.dxUrl = "/maps/dem";
comjs.fylzPro = "/mock/fylzprovince.json";
comjs.fylzCity = "/mock/fylzcity.json";
comjs.fylzCountry = "/mock/fylzcountry.json";
comjs.fylzStation = "/mock/fylzstation.json";
comjs.qhzsPro = "/mock/qxprovince.json";
comjs.qhzsCity = "/mock/qxcity.json";
comjs.qhzsCountry = "/mock/qxcountry.json";
comjs.cityCountyS = '/mock/catalogs.json';
comjs.checkList = '/mock/fylzCheck.json';
//comjs.qhzsCountry = "/mock/a.json";
comjs.qhzsStation = "/mock/qxstation.json";
comjs.stations = '/mock/a.json';
// 是否是在线接口
comjs.isOnline = true;
comjs.isThree = localStorage.getItem("isThree")==null?"sanwei":localStorage.getItem("isThree");

comjs.color1 = "#0CDE4E";
comjs.color2 = "#32F3A9";
comjs.color3 = "#2C9DE3";
comjs.color4 = "#6AA6C9";
comjs.color5 = "#737373";
// comjs.color1 = "#FFCC00";
// comjs.color2 = "#0BD74E";
// comjs.color3 = "#E36CA7";
// comjs.color4 = "#0D83D6";
// comjs.color5 = "#707070";

//cesium所需对象，容器，坐标，量测，marker
comjs.viewer = null;
comjs.dataSources = null;
comjs.dataSources1 = null;
comjs.dataSources2 = null;
comjs.x = null;
comjs.y = null;
comjs.aa = null;
comjs.measureSurface = null;
comjs.drawControl;
comjs.bindMarkerEx = null;
comjs.markers = [];
comjs.entity = null;
comjs.vtxfTerrainProvider = null;
comjs.currLayer = null;
comjs.imageLayer1 = null;

if(comjs.isOnline){
    comjs.imageLayer1 = new Cesium.UrlTemplateImageryProvider({
        url: "/maps/img/{z}/{x}/{y}.png"
    })
    comjs.imageLayer2 = new Cesium.UrlTemplateImageryProvider({
        url: "/maps/shiliang/{z}/{x}/{y}.png"
    })
}else{
    comjs.imageLayer1 = new Cesium.UrlTemplateImageryProvider({
        url: "http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
        // url: urll + "lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
    })
    comjs.imageLayer2 = new Cesium.UrlTemplateImageryProvider({
        url: "https://webst02.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}"
        //url: url2 + "style=7&x={x}&y={y}&z={z}"
    })
}
//三维球初始化
comjs.cesiumInit=function(){
        comjs.viewer = new Cesium.Viewer( "cesiumContainer" ,{    
            //sceneMode : Cesium.SceneMode.SCENE2D,//初始场景模式 为二维
            animation : false,//是否创建动画小器件，左下角仪表    
            baseLayerPicker : false,//是否显示图层选择器    
            fullscreenButton : false,//是否显示全屏按钮    
            geocoder : false,//是否显示geocoder小器件，右上角查询按钮    
            homeButton : false,//是否显示Home按钮    
            infoBox : false,//是否显示信息框    
            sceneModePicker : false,//是否显示3D/2D选择器    
            selectionIndicator : false,//是否显示选取指示器组件    
            timeline : false,//是否显示时间轴    
            navigationHelpButton : false,//是否显示右上角的帮助按钮 
            preserveDrawingBuffer: true,//通过canvas.toDataUrl()实现截图需要   
            scene3DOnly : true, //如果设置为true，则所有几何图形以3D模式绘制以节约GPU资源 );  
            // terrainProvider: vtxfTerrainProvider,
            // imageryProvider: new Cesium.MapboxImageryProvider({
            //     mapId : 'mapbox.satellite',
            //     accessToken: 'pk.eyJ1IjoiYW5hbHl0aWNhbGdyYXBoaWNzIiwiYSI6ImNpd204Zm4wejAwNzYyeW5uNjYyZmFwdWEifQ.7i-VIZZWX8pd1bTfxIVj9g'
            // }),
            //内网部署，禁止调用
            imageryProvider: Cesium.createTileMapServiceImageryProvider({
                url: Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
            })
        });
        //内网路网服务
        // comjs.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
        //     url: "/maps/shp/{z}/{x}/{y}.png"
        // }));
        if(comjs.isOnline){
            if(comjs.isThree=="sanwei"){
                console.log('在线三维')
                let url="/maps/dem";
                comjs.viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
                    url : url,
                    requestVertexNormals : true,
                    requestWaterMask: true //水波纹
                });
                comjs.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
                    url: "/maps/img/{z}/{x}/{y}.png"
                }));
            }else{
                console.log('在线二维')
                comjs.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
                    url: "/maps/shiliang/{z}/{x}/{y}.png"
                }));
            }
        }else{
            console.log(comjs.isThree);
            if(comjs.isThree=="sanwei"){
                console.log('离线三维')
                comjs.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
                    url: "http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
                    // url: urll + "lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
                }));
                var urlon="https://www.supermapol.com/realspace/services/3D-stk_terrain/rest/realspace/datas/info/data/path";
                comjs.viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
                    url : urlon,
                    requestVertexNormals : true,
                    requestWaterMask: true //水波纹
                });
            }else{
                console.log('离线二维')
                comjs.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
                    url: "https://webst02.is.autonavi.com/appmaptile?style=7&x={x}&y={y}&z={z}"
                }));
            }
        }
        // comjs.viewer.scene.debugShowFramesPerSecond = true;
        var scene = comjs.viewer.scene;
        var canvas = comjs.viewer.canvas;
        var camera = comjs.viewer.camera;
        scene.screenSpaceCameraController.minimumZoomDistance=100;
        comjs.viewer.clock.onTick.addEventListener(function () {
            setMinCamera();
        })
        var setMinCamera = function () {
            if(camera.pitch > 0){
                scene.screenSpaceCameraController.enableTilt = false;
            }
        }
	    var mousePosition,startMousePosition;
	    var handler = new Cesium.ScreenSpaceEventHandler(comjs.viewer.canvas);
	    handler.setInputAction(function(movement) { 
	        mousePosition=startMousePosition= Cesium.Cartesian3.clone(movement.position);
	        handler.setInputAction(function(movement) {
	            mousePosition = movement.endPosition;
	            var y = mousePosition.y - startMousePosition.y;
	            if(y>0){
	                comjs.viewer.scene.screenSpaceCameraController.enableTilt = true;
	            }
	        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
	    }, Cesium.ScreenSpaceEventType.MIDDLE_DOWN);
		comjs.viewer.camera.setView({
		    destination: Cesium.Cartesian3.fromDegrees(116.36115,39.916927,100000)
		});
    //下列属性，只能控制鼠标滚轮的 放大缩小。无法控制zoomIn和zoomOut
    comjs.viewer.scene.screenSpaceCameraController.minimumZoomDistance = 1000; //相机的高度的最小值
    comjs.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 22000000;  //相机高度的最大值
    // comjs.viewer.scene.screenSpaceCameraController._minimumZoomRate = 30000;   // 设置相机缩小时的速率h
    // comjs.viewer.scene.screenSpaceCameraController._maximumZoomRate=  27000    //设置相机放大时的速率
    //加载shp转换的geojson格式文件
    // Cesium.Math.setRandomNumberSeed(0);//需要研究该方法的含义作用
    var promise = Cesium.GeoJsonDataSource.load('/1.json',{
        stroke:  Cesium.Color.YELLOWGREEN,
        strokeWidth : 3,
        fill:Cesium.Color.SKYBLUE.withAlpha(0),
        clampToGround: true //开启贴地
    });
    var promise1 = Cesium.GeoJsonDataSource.load('/shi1.json',{//边界线
        stroke: Cesium.Color.YELLOWGREEN,
        strokeWidth : 3,
        // fill: Cesium.Color.RED.withAlpha(0.5),
        fill: new Cesium.Color(72,125,173,1),
        clampToGround: true //开启贴地
    });
    var promise2 = Cesium.GeoJsonDataSource.load('/xian1.json',{//边界线
        stroke: Cesium.Color.YELLOWGREEN,
        // fill: Cesium.Color.PINK.withAlpha(0.5),
        fill: new Cesium.Color(72,125,173,1),
        strokeWidth: 3,
        clampToGround: true //开启贴地
    });
    promise.then(function (dataSource) {
        comjs.dataSources = comjs.viewer.dataSources;
        comjs.dataSources.add(dataSource);
        comjs.dataSources.get(0).show=true;
        // var entities = dataSource.entities.values;
        // var colorHash = {};
        // for (var i = 0; i < entities.length;i++) {
        //     var entity = entities[i];
        //     var color = colorHash[name];
        //     var name = entity.name;
        //     if (!color) {
        //         color =Cesium.Color.fromRandom({
        //             alpha: 1.0
        //         });
        //         colorHash[name] = color;
        //     }
        //     entity.polygon.material = color;
        //     entity.polygon.outline = false;
        //     entity.polygon.extrudedHeight =10000.0;
        // }
    });
    promise1.then(function (dataSource) {
        comjs.viewer.dataSources.add(dataSource);
        comjs.viewer.dataSources.get(0).show=true;
        comjs.viewer.dataSources.get(1).show=false;
        comjs.viewer.dataSources.get(2).show=false;
        // var entities = dataSource.entities.values;
        // var colorHash = {};
        // for (var i = 0; i < entities.length;i++) {
        //     var entity = entities[i];
        //     var name = entity.name;
        //     if (!color) {
        //         color =Cesium.Color.fromRandom({
        //             alpha: 0.3
        //         });
        //         colorHash[name] = color;
        //     }
        //     entity.polygon.material = Cesium.Color.AQUA;
        //     entity.polygon.outline = false;
        //     entity.polygon.extrudedHeight =5000.0;
        // }
    });
    promise2.then(function (dataSource) {
        comjs.viewer.dataSources.add(dataSource);
        // comjs.viewer.dataSources.get(0).show=false;
        // comjs.viewer.dataSources.get(1).show=false;
        comjs.viewer.dataSources.get(2).show=false;
    });
    // promise3.then(function (dataSource) {
    //     comjs.viewer.dataSources.add(dataSource);
    //     comjs.viewer.dataSources.get(3).show=false;
    // });
    // promise4.then(function (dataSource) {
    //     comjs.viewer.dataSources.add(dataSource);
    //     comjs.viewer.dataSources.get(4).show=false;
    // });
    // blackMarble.alpha = 1;    //透明度
    // blackMarble.brightness = 0.3; //亮度   暗---亮： 0-1
    // comjs.viewer.flyTo(promise);
    // comjs.viewer.dataSources.destroy()
    
},
//2D,3D切换
comjs.threeTwo = function(){
    let scene = comjs.viewer.scene;
    scene.morphTo2D();

}
comjs.getYX = function(){
    if(comjs.isOnline){
        let url="/maps/dem";
        comjs.viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
            url : url,
            requestVertexNormals : true,
            requestWaterMask: true //水波纹
        });
    }else{
        comjs.viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
            url : "https://www.supermapol.com/realspace/services/3D-stk_terrain/rest/realspace/datas/info/data/path",
            requestVertexNormals : true,
            requestWaterMask: true //水波纹
        });
    }
    comjs.currLayer = comjs.imageLayer1;
    comjs.viewer.imageryLayers.addImageryProvider(comjs.currLayer)
}
comjs.getSL = function(){
    comjs.viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider({});
    comjs.currLayer = comjs.imageLayer2;
    comjs.viewer.imageryLayers.addImageryProvider(comjs.currLayer)
}
comjs.twoThree = function(){
    let scene = comjs.viewer.scene;
    scene.morphTo3D()
},
comjs.removeAll = function(){
    comjs.viewer.entities.removeAll();
}
//向左旋转
comjs.rotate = function(){
    comjs.viewer.camera.rotateLeft(Cesium.Math.toDegrees(0.005).toFixed(2));
},
//放大
comjs.zoomIn=function(h){
    comjs.viewer.camera.zoomIn(h);
    var height=comjs.viewer.camera.positionCartographic.height;
    //滚动时事件穿透，鼠标在元素上时仍可缩放地球
    if(height<100000){
        $('div[id^="popup-fylzStation2"]').show();
        //$('div[id^="popup-fylzStation1"]').hide();
        $('div[id^="popup-fylzCity"]').hide();
    //that.$comjs.viewer.camera.setView({
    //   destination : Cesium.Cartesian3.fromRadians(that.$comjs.viewer.camera.positionCartographic.longitude, that.$comjs.viewer.camera.positionCartographic.latitude, 100000)
    //});
    }
    if(height>100000 && height< 600000){
        $('div[id^="popup-fylzStation2"]').hide();
        $('div[id^="popup-fylzStation1"]').show();
        $('div[id^="popup-fylzCity"]').hide();
    }
    if(height>600000){
        $('div[id^="popup-fylzStation2"]').hide();
        $('div[id^="popup-fylzStation1"]').hide();
        $('div[id^="popup-fylzCity"]').show();
    //  that.$comjs.viewer.camera.setView({
    //      destination : Cesium.Cartesian3.fromRadians(that.$comjs.viewer.camera.positionCartographic.longitude, that.$comjs.viewer.camera.positionCartographic.latitude, 10000000)
    //  });
    }
},
//缩小
comjs.zoomOut=function(h){
    comjs.viewer.camera.zoomOut(h);
    var height=comjs.viewer.camera.positionCartographic.height;
    console.log(height)
    //滚动时事件穿透，鼠标在元素上时仍可缩放地球
    if(height<100000){
        $('div[id^="popup-fylzStation2"]').show();
        //$('div[id^="popup-fylzStation1"]').hide();
        $('div[id^="popup-fylzCity"]').hide();
    }
    if(height>100000 && height< 600000){
        $('div[id^="popup-fylzStation2"]').hide();
        $('div[id^="popup-fylzStation1"]').show();
        $('div[id^="popup-fylzCity"]').hide();
    }
    if(height>600000){
        $('div[id^="popup-fylzStation2"]').hide();
        $('div[id^="popup-fylzStation1"]').hide();
        $('div[id^="popup-fylzCity"]').show(); 
    }
},
//定位及视角
comjs.onCenter = function(x,y,h){
    comjs.viewer.camera.flyTo({ 
        destination :  Cesium.Cartesian3.fromDegrees(x,y, h), // 设置位置
        orientation: {
            heading : Cesium.Math.toRadians(0), // 方向
            pitch : Cesium.Math.toRadians(-90.0),// 倾斜角度
            roll : 0
        },
        // duration:2, // 设置飞行持续时间，默认会根据距离来计算
        // complete: function () {
        //     // 到达位置后执行的回调函数
        //     console.log('到达目的地');
        // },
        // cancle: function () {
        //     // 如果取消飞行则会调用此函数
        //     console.log('飞行取消')
        // },
        // pitchAdjustHeight: -90, // 如果摄像机飞越高于该值，则调整俯仰俯仰的俯仰角度，并将地球保持在视口中。
        // maximumHeight:500000, // 相机最大飞行高度
        // flyOverLongitude: 100, // 如果到达目的地有2种方式，设置具体值后会强制选择方向飞过这个经度
    });

}
comjs.onCenterR = function(x,y,h){ 
    comjs.viewer.camera.flyTo({
        destination :  Cesium.Cartesian3.fromDegrees(x ,(y - 0.1), h), // 设置位置
        orientation: {
            heading : Cesium.Math.toRadians(0), // 方向
            pitch : Cesium.Math.toRadians(-10), // 倾斜角度
            roll :  0
        },
        // duration:2, // 设置飞行持续时间，默认会根据距离来计算
        // complete: function () {
        //     // 到达位置后执行的回调函数
        //     console.log('到达目的地');
        // },
        // cancle: function () {
        //     // 如果取消飞行则会调用此函数
        //     console.log('飞行取消')
        // },
        // pitchAdjustHeight: -90, // 如果摄像机飞越高于该值，则调整俯仰俯仰的俯仰角度，并将地球保持在视口中。
        // maximumHeight:500000, // 相机最大飞行高度
        // flyOverLongitude: 100, // 如果到达目的地有2种方式，设置具体值后会强制选择方向飞过这个经度
    });

}
//量测功能，距离测量
comjs.drawPolyline = function(){
    comjs.measureSurface = new mars3d.Measure({
        viewer: comjs.viewer,
        terrain: false
    }); 
    comjs.measureSurface.measuerLength();//测量长度
    //measureSurface.measureArea();//测量面积                                 
    //measureSurface.measureHeight();//测量高度
    //measureSurface.clearMeasure();//清除
},
//面积测量
comjs.measureArea = function(){
    let measureSurface = new mars3d.Measure({
        viewer: comjs.viewer,
        terrain: false
    }); 
    measureSurface.measureArea();//测量面积                                 
},
//高度测量
comjs.measureHeight= function(){
    let measureSurface = new mars3d.Measure({
        viewer: comjs.viewer,
        terrain: false
    }); 
    measureSurface.measureHeight();//测量高度
    //measureSurface.clearMeasure();//清除
},
//清除测量结果
comjs.clearMeasure = function(){
    comjs.measureSurface.clearMeasure();//清除测量结果                            
};
let reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;

String.prototype.colorRgba = function(){
	var sColor = this.toLowerCase();
	if(sColor && reg.test(sColor)){
		if(sColor.length === 4){
			var sColorNew = "#";
			for(var i=1; i<4; i+=1){
				sColorNew += sColor.slice(i,i+1).concat(sColor.slice(i,i+1));	
			}
			sColor = sColorNew;
		}
		//处理六位的颜色值
		var sColorChange = [];
		for(var i=1; i<7; i+=2){
			sColorChange.push(parseInt("0x"+sColor.slice(i,i+2)));	
		}
		return "rgba(" + sColorChange.join(",") + ",100%)";
	}else{
		return sColor;	
	}
};
comjs.addF1 = function(markerArr){
//setTimeOut(function(){},200)
},

comjs.addError1 = function(objPopup){
    function updateViewPoint(eleId, cartesian) {
        var point = Cesium.SceneTransforms.wgs84ToWindowCoordinates(comjs.viewer.scene, cartesian);
        if (point == null) return false;
        var $view = $("#" + eleId);
        var x = point.x - ($view.width() / 2);
        var y = point.y - $view.height();
        $view.css('transform', 'translate3d(' + x + 'px,' + y + 'px, 0)');
        return true;
    }
    function bind2scene() {
        for (var i in objPopup) {
            var item = objPopup[i];
            updateViewPoint(i, item.cartesian);
        }
    }
    comjs.viewer.scene.postRender.addEventListener(bind2scene);
},
//负氧离子省及站点页面marker
comjs.addF = function(markerArr){
    var markerArr=[];
    var markerArr1=[];
    $.ajax({
        type:"GET",
        url:comjs.fylzProUrl,
        dataType: "json",
        success: function(data){
            for(var i=0;i<data.StationEPAdatas.length;i++){
                markerArr1[i]={};
                markerArr1[i].x=data.StationEPAdatas[i].Lon;
                markerArr1[i].y=data.StationEPAdatas[i].Lat;
                markerArr1[i].markerImg='./mark.png'
                markerArr1[i].name=data.StationEPAdatas[i].StationName;
                markerArr1[i].name1=data.StationEPAdatas[i].City;
                markerArr1[i].level=data.StationEPAdatas[i].level;
                markerArr1[i].negative_K04=parseInt(data.StationEPAdatas[i].negative_K04);
                markerArr1[i].MaxNegative_K04=data.StationEPAdatas[i].MaxNegative_K04;
                markerArr1[i].markerId = i;
                markerArr1[i].QXDJ=data.StationEPAdatas[i].QXDJ;
                switch(data.StationEPAdatas[i].Level){
                    case 1:{
                        markerArr1[i].num = 3;
                        markerArr1[i].Level='I';
                        markerArr1[i].markerColor='#0CDE4E';
                        markerArr1[i].canvas = '/siji.gif'
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr1[i].Color100=markerArr1[i].markerColor.colorRgba();
                        break;
                    }
                    case 2:{
                        markerArr1[i].num = 5;
                        markerArr1[i].Level='II';
                        markerArr1[i].markerColor='#32F3A9';
                        markerArr1[i].canvas = '/sanji.gif'
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr1[i].Color100=markerArr1[i].markerColor.colorRgba();
                        break;
                    }
                    case 3:{
                        markerArr1[i].num = 7;
                        markerArr1[i].Level='III';
                        markerArr1[i].markerColor='#63B5E6';
                        markerArr1[i].canvas = '/erji.gif'
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr1[i].Color100=markerArr1[i].markerColor.colorRgba();
                        break;
                    }
                    case 4:{
                        markerArr1[i].num = 9;
                        markerArr1[i].Level='IV';
                        markerArr1[i].markerColor='#FF680D';
                        markerArr1[i].canvas = '/yiji.gif'
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr1[i].Color100=markerArr1[i].markerColor.colorRgba();
                        break;
                    }
                    case 5:{
                        markerArr1[i].num = 11;
                        markerArr1[i].Level='VI';
                        markerArr1[i].markerColor='#A1A1A1';
                        markerArr1[i].canvas = '/1.gif'
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr1[i].Color100=markerArr1[i].markerColor.colorRgba();
                        break;
                    }
                }

                //markerArr[i].QXDJ=data.CityEPAdatas[i].QXDJ;
            }
            //添加负氧离子站点
            comjs.addFYMarkers(markerArr1); 
            $('div[id^="popup-fylzStation"]').hide()
        
            for(var i=0;i<data.CityEPAdatas.length;i++){
                markerArr[i]={};
                markerArr[i].x=data.CityEPAdatas[i].Lon;
                markerArr[i].y=data.CityEPAdatas[i].Lat;
                markerArr[i].markerImg='./mark.png'
                markerArr[i].name=data.CityEPAdatas[i].City;
                markerArr[i].level=data.CityEPAdatas[i].level;
                markerArr[i].negative_K04=parseInt(data.CityEPAdatas[i].negative_K04);
                markerArr[i].MaxNegative_K04=data.CityEPAdatas[i].MaxNegative_K04;    
                markerArr[i].markerId=i;
                markerArr[i].QXDJ=data.CityEPAdatas[i].QXDJ;
                switch(data.CityEPAdatas[i].Level){
                    case 1:{
                        markerArr[i].Level='I';
                        markerArr[i].markerColor='#0CDE4E';
                        // gradient
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr[i].Color100=markerArr[i].markerColor.colorRgba();
                        break;
                    }
                    case 2:{
                        markerArr[i].Level='II';
                        markerArr[i].markerColor='#32F3A9';
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr[i].Color100=markerArr[i].markerColor.colorRgba();
                        break;
                    }
                    case 3:{
                        markerArr[i].Level='III';
                        markerArr[i].markerColor='#63B5E6';
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr[i].Color100=markerArr[i].markerColor.colorRgba();
                        break;
                    }
                    case 4:{
                        markerArr[i].Level='IV';
                        markerArr[i].markerColor='#FF680D';
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr[i].Color100=markerArr[i].markerColor.colorRgba();
                        break;
                    }
                    case 5:{
                        markerArr[i].Level='VI';
                        markerArr[i].markerColor='#A1A1A1';
                        //markerArr[i].Color0=markerArr[i].markerColor.colorRgba0();
                        markerArr[i].Color100=markerArr[i].markerColor.colorRgba();
                        break;
                    }
                }
            }
            setMarker();  
        }
    });
    var objPopup = {};
    var infoDiv = '<div id="pupup-all-view" ></div>';
    //追加到cesium容器中
    $("#cesiumContainer").append(infoDiv);
    function updateViewPoint(eleId, cartesian) {
        var point = Cesium.SceneTransforms.wgs84ToWindowCoordinates(comjs.viewer.scene, cartesian);
        if (point == null) return false;
        
        var $view = $("#" + eleId);
        var x = point.x - ($view.width() / 2);
        var y = point.y - $view.height();
        $view.css('transform', 'translate3d(' + x + 'px,' + y + 'px, 0)');
        return true;
    }

    //setTimeOut(function(){},200)
    function setMarker(){
        for(var i = 0;i<markerArr.length;i++){
            comjs.entity = comjs.viewer.entities.add({
                name :markerArr[i].name,
                position : Cesium.Cartesian3.fromDegrees(markerArr[i].x,markerArr[i].y,-100),
                billboard : {
                    image : markerArr[i].markerImg,
                    verticalOrigin : Cesium.VerticalOrigin.BOTTOM
                },
            });
            //绑定在球上//获取实体
            var entity = comjs.entity;
            var position = entity._position._value;
            var cartesian;
            if (entity.billboard || entity.label || entity.point) {
                cartesian = position;
            } 
            
            var idName = markerArr[i].markerId;
            var Level=markerArr[i].Level;
            var eleId = 'popup-fylzCity' + i + "-" + Level + "-";
            objPopup[eleId] = {
                cartesian: cartesian
            };
            //显示内容
            var inhtml;
                //各市marker
                inhtml = `<div id="${eleId}" class="cesium-popup" style="pointer-events: none;">
                            <div class="cesium-popup-content-wrapper" style="box-shadow: 0 0px 0px rgba(0,0,0,0);color:#fff;overflow:inherit">
                                <div id="fuyangProvinceMarker" class="cesium-popup-content">
                                    <div style="float:left;user-select: none;">
                                        <div>
                                            <span style="font-size:20px">${markerArr[i].negative_K04}</span>
                                            <span>/${markerArr[i].MaxNegative_K04}</span>
                                        </div>
                                        <div class="cityName" style="background:linear-gradient(90deg,rgba(255,255,255,0%) 0%,${markerArr[i].Color100} 100%)" data-cityX="${markerArr[i].x}" data-cityY="${markerArr[i].y}" data-name="${markerArr[i].name}" style="background:linear-gradient(90deg,rgba(68,169,190,0) 0%,rgba(39,203,143,1) 100%);text-align:right;" >
                                            <div class="cityNameClick" style="color:white;text-decoration:none">    
                                                <span style="pointer-events:auto;">${markerArr[i].name} </span>    
                                            </div>
                                        </div>
                                        <div class="henqingxin" style="background:${markerArr[i].markerColor}">${markerArr[i].QXDJ}</div>
                                        <div class="levelCir" style="background:${markerArr[i].markerColor}">${markerArr[i].Level}</div>
                                    </div>
                                    <div style="float:left;width:80px;margin-top:36px">
                                        <div style="float:left;width:50px;height:1px;background:#59E1FE"></div>
                                        <div style="float:left;width:30px;height:1px;background:#59E1FE;transform-origin:left;transform:rotate(30deg);"></div>
                                    </div>
                                    <div id="cubes" style="float:left;display：none;">
                                        <div class="wrap">
                                            <div class="cube">
                                                <div class="front" style="background:${markerArr[i].markerColor}"></div>
                                                <div class="back" style="background:${markerArr[i].markerColor}"></div>
                                                <div class="top" style="background:${markerArr[i].markerColor}"></div>
                                                <div class="bottom" style="background:${markerArr[i].markerColor}"></div>
                                                <div class="left" style="background:${markerArr[i].markerColor}"></div>
                                                <div class="right" style="background:${markerArr[i].markerColor}"></div>
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                                
                            </div>
                             </div>`;
                $("#pupup-all-view").append(inhtml);
                $(document).on('click','.cityName', function(){
                    localStorage.setItem('headerCity', $(this).attr('data-name'));
                    comjs.aa = localStorage.getItem('headerCity');
                    localStorage.setItem('cityX', $(this).attr('data-cityX'));
                    localStorage.setItem('cityY', $(this).attr('data-cityY'));
                    // window.location.href= comjs.localUrl + "/city/" + $(this).attr('data-name');
                });
            //计算显示位置
            updateViewPoint(eleId, cartesian);
            //计算实体位置，跟随三维球缩放和旋转
        }
    }
    
    function bind2scene() {
        for (var i in objPopup) {
            var item = objPopup[i];
            updateViewPoint(i, item.cartesian);
        }
    }
    comjs.viewer.scene.preRender.addEventListener(bind2scene);//此处渲染方法，preRender  
},
//负氧离子站点页面marker
comjs.addFYMarkers = function(markerArr){
    function updateViewPoint(eleId, cartesian, popup) {
        var point = Cesium.SceneTransforms.wgs84ToWindowCoordinates(comjs.viewer.scene, cartesian);
        if (point == null) return false;
        var $view = $("#" + eleId);
        var x = point.x - ($view.width() / 2);
        var y = point.y - $view.height();
        if (popup && (typeof popup === 'object') && popup.anchor) {
            x += popup.anchor[0];
            y += popup.anchor[1];
        }
        $view.css('transform', 'translate3d(' + x + 'px,' + y + 'px, 100px)');
        return true;
    }
    // var height=$comjs.viewer.camera.positionCartographic.height;
    var objPopup = {};
    for(var i = 0;i < markerArr.length;i++){
        comjs.entity = comjs.viewer.entities.add({
            name :markerArr[i].name,
            position : Cesium.Cartesian3.fromDegrees(markerArr[i].x,markerArr[i].y,0),
            billboard : {
                image : markerArr[i].markerImg,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                clampToGround: true
            },

        });
        var entity = comjs.entity;
        var position = entity._position._value;
        var cartesian;
        if (entity.billboard || entity.label || entity.point) {
            cartesian = position;
        } 
        show(entity, cartesian); 
        
        function show(entity, cartesian, idName ) {
            var Level=markerArr[i].Level;
            var idName = markerArr[i].markerId;
            var eleId = 'popup-fylzStation' + i + "-" + Level + "-";
            objPopup[eleId] = {
                popup: entity.popup,
                cartesian: cartesian
            };
            
            var inhtml;
            if (typeof entity.popup === 'object')
                inhtml = entity.popup.html;
            else
                inhtml = entity.popup;
            
            if (typeof inhtml === 'function') {
                inhtml = inhtml(entity);//回调方法
            }
            inhtml = `<div id="${eleId}" class="cesium-popup" style="pointer-events: none;">
                        <div id="fuyangCityMarker${i}" class="cesium-popup-content-wrapper" style="position:relative;box-shadow: 0 0px 0px rgba(0,0,0,0);color:#fff;overflow:inherit" >
                            <div class="cesium-popup-content">
                                <div class="fylzStationName" style="width:90%;margin:0 auto;text-align:center;background:rgba(255,255,255,.5)" 
                                    data-name="${markerArr[i].name}"
                                    data-name="${markerArr[i].name1}"
                                    data-stationX="${markerArr[i].x}" 
                                    data-stationY="${markerArr[i].y}">
                                    <span style="display:block;margin:o auto;pointer-events: auto;cursor:pointer;">${markerArr[i].name}</span>
                                </div>
                                <div class="fuyangliziNum" style="background:linear-gradient(0deg,${markerArr[i].Color100} 0%,rgba(13,131,214,0) 100%)" style="pointer-events: auto;" 
                                    data-stationX="${markerArr[i].x}" 
                                    data-stationY="${markerArr[i].y}">${markerArr[i].negative_K04}个</div>
                                <div class="fuyangCanvas" style="background:linear-gradient(0deg,${markerArr[i].Color100} 0%,rgba(13,131,214,0) 100%);">
                                    <div class="fuyanglizi" >
                                        <img id="${eleId}canvas" width="76" height="87" src="${markerArr[i].canvas}" />
                                    </div>
                                </div>
                            </div>
                            <div class="yuanquan" style="background:${markerArr[i].Color100}">
                                <div class="xiaoyuanquan"></div>
                            </div>
                        </div>                    
                 </div>`;
            $("#pupup-all-view").append(inhtml);
            $(document).on('click','.fylzStationName', function(){   
                localStorage.setItem('headerStation', $(this).attr('data-name'));
                localStorage.setItem('stationX', $(this).attr('data-stationX'));
                localStorage.setItem('stationY', $(this).attr('data-stationY'));
                // comjs.onCenterR($(this).attr('data-stationX'),$(this).attr('data-stationY'),7000)
                window.location.href= comjs.localUrl + "/station/" + $(this).attr('data-name');
            });
            // $(document).on('click','.yuanquan', function(){
            //     $(this).prev().children('.fuyangliziNum').toggle();
            //     $(this).prev().children('.fuyangCanvas').toggle();
            // });
            // $(document).on('click', 'div[id^="popup-fylzStation"]',function(){

            // })
            // $('.cesium-popup').on('click','.qixiangCityName', function(){
            //     localStorage.setItem('headerStation', $(this).attr('data-name'));
            //     localStorage.setItem('stationX', $(this).attr('data-stationX'));
            //     localStorage.setItem('stationY', $(this).attr('data-stationY'));
            //     window.location.href="http://192.168.45.103:8080/stationW/" + $(this).attr('data-name');
            //     console.log("dsafsdf");               
            // });
            
            updateViewPoint(eleId, cartesian, entity.popup);
        
        }
    }
    // function Random(min , max){
    //     return Math.random()*(max-min)+min;
    // }
       
    //     var w = 76;
    //     var h = 87;
    //     var cxt;
    //     var newArr = [];
    //     function draw(){ //清除两次
    //         for(var i=0;i<a.length;i++){
    //             var id = a[i].id + 'canvas';
    //             var num =  parseInt(a[i].data-num);
    //             var myMap = document.getElementById(id);
    //             var cxt = myMap.getContext('2d');
    //             cxt.clearRect(0, 0, w, h);
    //             for(let i=0;i<10;i++){
    //                 var img = new Image();
    //                 img.src = "/xuehua.png";
    //                 newArr.push(img)
    //                 cxt.drawImage(img,Random(0,w),Random(0,h),18,18)
    //             } 
    //         }
            
    //         for(let j=0;j<num;j++){
    //             cxt.clearRect(0, 0, w, h);
    //             cxt.drawImage(newArr[j], x, y, 18, 18);
    //             var x = Random(0,w-18); //图片在画布上的位置
    //             var y = Random(0,h); //图片在画布上的位置
    //             var vX = Random(-1,1);
    //             var vY = Random(1,2);
    //             x += vX;
    //             y -= vY;
    //             if( x - 18 < 0) {  x = Random(0,w-18) } //图片左上角为图片位置
    //             if( y  < 0 ) { y = Random(0,h) }
    //         }
    //     }
    
    // var  timer =  window.setInterval(draw, 300);

    function bind2scene() {
        for (var i in objPopup) {
            var item = objPopup[i];
            updateViewPoint(i, item.cartesian, item.popup);
        }
    }
    // 添加市级页面时已上传
    comjs.viewer.scene.postRender.addEventListener(bind2scene);
    // comjs.viewer.mars.popup.show(entity,cartesian );
},
//气候指数marker
comjs.addQ = function(){
    var infoDiv = '<div id="pupup-all-view" style=""></div>';
    //追加到cesium容器中
    $("#cesiumContainer").append(infoDiv);
    var markerArr=[];
    var markerArr1 = [];
    $.ajax({
        type:"GET",
        url: comjs.qhzsPro,
        dataType: "json",
        success: function(data){
            for(var i=0;i<data.StationQXZs.length;i++){
                markerArr[i]={};
                markerArr[i].x=data.StationQXZs[i].Lon;
                markerArr[i].y=data.StationQXZs[i].Lat;
                markerArr[i].markerImg='./mark.png';
                markerArr[i].name=data.StationQXZs[i].StationName;
                markerArr[i].name1=data.StationQXZs[i].City;
                markerArr[i].level=data.StationQXZs[i].level;
                markerArr[i].BCMI = parseInt(data.StationQXZs[i].BCMI);
                markerArr[i].HCI = parseInt(data.StationQXZs[i].HCI);
                markerArr[i].THI = parseInt(data.StationQXZs[i].THI);
                markerArr[i].WCI = parseInt(data.StationQXZs[i].WCI);
                markerArr[i].markerId = i;
            }
            comjs.addQHMarkers(markerArr);
            console.log(data.CityQXZs)
            for(var i=0;i<data.CityQXZs.length;i++){
                markerArr1[i]={};
                markerArr1[i].x=data.CityQXZs[i].Lon;
                markerArr1[i].y=data.CityQXZs[i].Lat;
                markerArr1[i].markerImg='./mark.png';
                markerArr1[i].name=data.CityQXZs[i].StationName;
                markerArr1[i].name1=data.CityQXZs[i].City;
                markerArr1[i].level=data.CityQXZs[i].level;
                markerArr1[i].BCMI = parseInt(data.CityQXZs[i].BCMI);
                markerArr1[i].HCI = parseInt(data.CityQXZs[i].HCI);
                markerArr1[i].THI = parseInt(data.CityQXZs[i].THI);
                markerArr1[i].WCI = parseInt(data.CityQXZs[i].WCI);
                markerArr1[i].BCMIDJ = parseInt(data.CityQXZs[i].BCMIDJ);
                markerArr1[i].HCIDJ = parseInt(data.CityQXZs[i].HCIDJ);
                markerArr1[i].THIDJ = parseInt(data.CityQXZs[i].THIDJ);
                markerArr1[i].WCIDJ = parseInt(data.CityQXZs[i].WCIDJ);
                markerArr1[i].markerId = i;
            }
            comjs.addQHCMarkers(markerArr1);
        }
    })
}
//气候指数marker
comjs.addQHMarkers = function(markerArr){
    function updateViewPoint(eleId, cartesian, popup) {
        var point = Cesium.SceneTransforms.wgs84ToWindowCoordinates(comjs.viewer.scene, cartesian);
        if (point == null) return false;
        var $view = $("#" + eleId);
        var x = point.x - ($view.width() / 2);
        var y = point.y - $view.height();
        if (popup && (typeof popup === 'object') && popup.anchor) {
            x += popup.anchor[0];
            y += popup.anchor[1];
        }
        $view.css('transform', 'translate3d(' + x + 'px,' + y + 'px, 0)');
        return true;
    }
    // var height=$comjs.viewer.camera.positionCartographic.height;
    var objPopup = {};
    for(var i = 0;i < markerArr.length;i++){
        comjs.entity = comjs.viewer.entities.add({
            name :markerArr[i].name,
            position : Cesium.Cartesian3.fromDegrees(markerArr[i].x,markerArr[i].y,0),
            billboard : {
                image : markerArr[i].markerImg,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM
            },

        });
        var entity = comjs.entity;
        var position = entity._position._value;
        var cartesian;
        if (entity.billboard || entity.label || entity.point) {
            cartesian = position;
        } 
        show(entity, cartesian); 
        function show(entity, cartesian, idName ) {
            var idName = markerArr[i].markerId;
            var eleId = 'popup-Q' + i;
            objPopup[eleId] = {
                popup: entity.popup,
                cartesian: cartesian
            };
            var inhtml;
            if (typeof entity.popup === 'object')
                inhtml = entity.popup.html;
            else
                inhtml = entity.popup;
            
            if (typeof inhtml === 'function') {
                inhtml = inhtml(entity);//回调方法id="qixiangCity${i}"
            }
            inhtml = `<div id="${eleId}" class="cesium-popup" style="pointer-events: none;">
                        <div class="cesium-popup-content-wrapper" style="box-shadow: 0 0px 0px rgba(0,0,0,0);color:#fff;overflow:inherit">
                        <div class="cesium-popup-content" style="margin:0;">
                            <div class="cesium-popup-content-wrapper" style="box-shadow: 0 0px 0px rgba(0,0,0,0);color:#fff;overflow:inherit">
                                <div class="cesium-popup-content">
                                    <div class="qname" style="pointer-events: auto;cursor:pointer;"
                                        data-name="${markerArr[i].name}" 
                                        data-stationX="${markerArr[i].x}" 
                                        data-stationY="${markerArr[i].y}"
                                        style="width:100%;text-align:center">${markerArr[i].name}</div>
                                    <div class="qxzs">
                                        <div>${markerArr[i].name}</div>
                                        <span class="iconfont">&#xe600;</span>${markerArr[i].BCMI} &nbsp; 
                                        <span class="iconfont">&#xe690;</span>${markerArr[i].HCI} 
                                        <br/> 
                                        <span class="iconfont">&#xe607;</span>${markerArr[i].THI}&nbsp;
                                        <span class="iconfont">&#xe65e;</span>${markerArr[i].WCI}
                                    </div>                                                                   
                                    <div class="yuanquanBlue">
                                        <div class="xiaoyuanquan"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        </div>
                </div>`;
            $("#pupup-all-view").append(inhtml);
            $(document).on('click','.qname', function(){
                localStorage.setItem('headerStation', $(this).attr('data-name'));
                localStorage.setItem('stationX', $(this).attr('data-stationX'));
                localStorage.setItem('stationY', $(this).attr('data-stationY'));
                window.location.href=comjs.localUrl +"/stationW/" + $(this).attr('data-name');
            });
            //此处控制显引，开始用toggle不能解决，后来得知1.9以上版本取消该方法（但上面的方法里是可行的）。只能用下面的方法解决
            var state=0;
            $('body').on('click','.yuanquanBlue', function(){
                //不支持toggle,需要解决
                if(state==0){
                    $(this).prev('.qxzs').show()
                    state=1;
                }else  {
                    $(this).prev('.qxzs').hide()
                    state=0;
                }
                // $(this).prev().show();
                // $(this).prev().
            });
            // $('.cesium-popup').on('click','.qixiangCityName', function(){
            //     localStorage.setItem('headerStation', $(this).attr('data-name'));
            //     localStorage.setItem('stationX', $(this).attr('data-stationX'));
            //     localStorage.setItem('stationY', $(this).attr('data-stationY'));
            //     window.location.href="http://192.168.45.103:8080/stationW/" + $(this).attr('data-name');
            //     console.log("dsafsdf");               
            // });
            updateViewPoint(eleId, cartesian, entity.popup);
        }
    }
    function bind2scene() {
        for (var i in objPopup) {
            var item = objPopup[i];
            updateViewPoint(i, item.cartesian, item.popup);
        }
    }
    // 添加市级页面时已上传
    comjs.viewer.scene.postRender.addEventListener(bind2scene);
},
// comjs.changeGEOJson = function(a){
//     if(a==0){
//         comjs.viewer.dataSources.get(0).show=true;
//         comjs.viewer.dataSources.get(1).show=false;
//         comjs.viewer.dataSources.get(2).show=false;
//     }else if(a==1){
//         comjs.viewer.dataSources.get(0).show=false;
//         comjs.viewer.dataSources.get(1).show=true;
//         comjs.viewer.dataSources.get(2).show=false;
//     }else if(a==2){
//         comjs.viewer.dataSources.get(0).show=false;
//         comjs.viewer.dataSources.get(1).show=false;
//         comjs.viewer.dataSources.get(2).show=true;
//     }
   
// },
//气候指数marker
comjs.addQHCMarkers = function(markerArr){
    function updateViewPoint(eleId, cartesian, popup) {
        var point = Cesium.SceneTransforms.wgs84ToWindowCoordinates(comjs.viewer.scene, cartesian);
        if (point == null) return false;
        var $view = $("#" + eleId);
        var x = point.x - ($view.width() / 2);
        var y = point.y - $view.height();
        if (popup && (typeof popup === 'object') && popup.anchor) {
            x += popup.anchor[0];
            y += popup.anchor[1];
        }
        $view.css('transform', 'translate3d(' + x + 'px,' + y + 'px, 0)');
        return true;
    }
    // var height=$comjs.viewer.camera.positionCartographic.height;
    var objPopup = {};
    for(var i = 0;i < markerArr.length;i++){
        comjs.entity = comjs.viewer.entities.add({
            name :markerArr[i].name,
            position : Cesium.Cartesian3.fromDegrees(markerArr[i].x,markerArr[i].y,0),
            billboard : {
                image : markerArr[i].markerImg,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM
            },

        });
        var entity = comjs.entity;
        var position = entity._position._value;
        var cartesian;
        if (entity.billboard || entity.label || entity.point) {
            cartesian = position;
        } 
        show(entity, cartesian); 
        function show(entity, cartesian, idName ) {
            var idName = markerArr[i].markerId;
            var eleId = 'popup-QC' + i;
            objPopup[eleId] = {
                popup: entity.popup,
                cartesian: cartesian
            };
            var inhtml;
            if (typeof entity.popup === 'object')
                inhtml = entity.popup.html;
            else
                inhtml = entity.popup;
            
            if (typeof inhtml === 'function') {
                inhtml = inhtml(entity);//回调方法id="qixiangCity${i}"
            }
            inhtml = `<div id="${eleId}" class="cesium-popup">
                        <div class="cesium-popup-content-wrapper" style="box-shadow: 0 0px 0px rgba(0,0,0,0);color:#fff;overflow:inherit">
                        <div class="cesium-popup-content">
                            <div class="cesium-popup-content-wrapper" style="box-shadow: 0 0px 0px rgba(0,0,0,0);color:#fff;overflow:inherit">
                                <div class="cesium-popup-content">
                                    <div class="qcname"  style=""
                                        data-name="${markerArr[i].name1}" 
                                        data-stationX="${markerArr[i].x}" 
                                        data-stationY="${markerArr[i].y}"
                                        style="width:100%;text-align:center">${markerArr[i].name1}</div>
                                    <div class="qxzs" style="display:none">
                                        <span class="iconfont">&#xe600;</span>${markerArr[i].BCMI} &nbsp; 
                                        <span class="iconfont">&#xe690;</span>${markerArr[i].HCI} 
                                        <br/> 
                                        <span class="iconfont">&#xe607;</span>${markerArr[i].THI}&nbsp;
                                        <span class="iconfont">&#xe65e;</span>${markerArr[i].WCI}
                                    </div>                                                                   
                                    <div class="yuanquanBlue" style="background:red">
                                        <div class="xiaoyuanquan"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        </div>
                </div>`;
            $("#pupup-all-view").append(inhtml);
            $(document).on('click','.qcname', function(){
                localStorage.setItem('headerCity', $(this).attr('data-name'));
                localStorage.setItem('stationX', $(this).attr('data-stationX'));
                localStorage.setItem('stationY', $(this).attr('data-stationY'));
                window.location.href= comjs.localUrl +"/cityW/" + $(this).attr('data-name');
            });
            //此处控制显引，开始用toggle不能解决，后来得知1.9以上版本取消该方法（但上面的方法里是可行的）。只能用下面的方法解决
            var state=0;
            $('body').on('click','.yuanquanBlue', function(){
                //不支持toggle,需要解决
                if(state==0){
                    $(this).prev('.qxzs').show()
                    state=1;
                }else  {
                    $(this).prev('.qxzs').hide()
                    state=0;
                }
                // $(this).prev().show();
                // $(this).prev().
            });
            // $('.cesium-popup').on('click','.qixiangCityName', function(){
            //     localStorage.setItem('headerStation', $(this).attr('data-name'));
            //     localStorage.setItem('stationX', $(this).attr('data-stationX'));
            //     localStorage.setItem('stationY', $(this).attr('data-stationY'));
            //     window.location.href="http://192.168.45.103:8080/stationW/" + $(this).attr('data-name');
            //     console.log("dsafsdf");               
            // });
            updateViewPoint(eleId, cartesian, entity.popup);
        }
    }
    function bind2scene() {
        for (var i in objPopup) {
            var item = objPopup[i];
            console.log(item.cartesian)
            updateViewPoint(i, item.cartesian, item.popup);
        }
    }
    // 添加市级页面时已上传
    comjs.viewer.scene.postRender.addEventListener(bind2scene);
},
//绕点飞行测试
comjs.feixing = function(){
    var position=Cesium.Cartesian3.fromDegrees(112.315216, 39.5125612, 10000);
            comjs.viewer.scene.camera.flyTo({
			destination: Cesium.Cartesian3.fromDegrees(112.315216, 39.5125612, 20000),  //定位坐标点，建议使用谷歌地球坐标位置无偏差
			duration:1   //定位的时间间隔
		});
		setTimeout(function(){
			 flyExtent();
		},100);
		
		function  flyExtent(){
			// 相机看点的角度，如果大于0那么则是从地底往上看，所以要为负值，这里取-30度
		    var pitch = Cesium.Math.toRadians(-30);
		    // 给定飞行一周所需时间，比如10s, 那么每秒转动度数
		    var angle = 360 / 5;
		    // 给定相机距离点多少距离飞行，这里取值为5000m
		    var distance = 15000;
		    var startTime = Cesium.JulianDate.fromDate(new Date());
		    var stopTime = Cesium.JulianDate.addSeconds(startTime, 5, new Cesium.JulianDate());
		    comjs.viewer.clock.startTime = startTime.clone();  // 开始时间
		    comjs.viewer.clock.stopTime = stopTime.clone();     // 结速时间
		    comjs.viewer.clock.currentTime = startTime.clone(); // 当前时间
		    comjs.viewer.clock.clockRange = Cesium.ClockRange.CLAMPED; // 行为方式
		    comjs.viewer.clock.clockStep = Cesium.ClockStep.SYSTEM_CLOCK; // 时钟设置为当前系统时间; 忽略所有其他设置。
		    // 相机的当前heading
		    var initialHeading = comjs.viewer.camera.heading;
		    var Exection = function TimeExecution() {
		            // 当前已经过去的时间，单位s
		            var delTime = Cesium.JulianDate.secondsDifference(comjs.viewer.clock.currentTime, comjs.viewer.clock.startTime);
		            var heading = Cesium.Math.toRadians(delTime * angle) + initialHeading;
		            comjs.viewer.scene.camera.setView({
		                destination : position, // 点的坐标
		                orientation: {
		                    heading : heading,
		                    pitch : pitch,
		                }
		            });
		            comjs.viewer.scene.camera.moveBackward(distance);
		            if (Cesium.JulianDate.compare(comjs.viewer.clock.currentTime, comjs.viewer.clock.stopTime) >= 0) {
		                comjs.viewer.clock.onTick.removeEventListener(Exection);
		            }
		 
		    };
		    comjs.viewer.clock.onTick.addEventListener(Exection);
			
		}
}
// 添加省边界
comjs.addPloy = function(){
    var en=  comjs.viewer.entities.add({
          name:"浙江省面",
          polygon:{
              hierarchy:{
                  positions:Cesium.Cartesian3.fromDegreesArray(
                      [118.2129, 29.3994 , 118.7402, 29.707 , 118.916, 29.9707 , 118.916, 30.3223 , 119.3555, 30.4102 , 119.2676, 30.6299 , 119.4434, 30.6738 , 119.6191, 31.0693   ,   119.6191, 31.1133   ,   119.9707, 31.1572   ,   120.498, 30.8057   ,   120.9375, 31.0254   ,   121.2891, 30.6738   ,   121.9922, 30.8057   ,   122.6953, 30.8936   ,   122.8711, 30.7178   ,   122.959, 30.1465   ,   122.6074, 30.1025   ,   122.6074, 29.9268   ,   122.168, 29.5313   ,   122.3438, 28.8721   ,   121.9922, 28.8721   ,   121.9922, 28.4326   ,   121.7285, 28.3447   ,   121.7285, 28.2129   ,   121.4648, 28.2129   ,   121.5527, 28.0371   ,   121.2891, 27.9492   ,   121.1133, 27.4219   ,   120.6738, 27.334   ,   120.6738, 27.1582   ,   120.9375, 27.0264   ,   120.7617, 27.0264   ,   120.4102, 27.1582   ,   120.2344, 27.4219   ,   119.7949, 27.29   ,   119.6191, 27.6855   ,   119.2676, 27.4219   ,   118.916, 27.4658 , 118.7402, 28.0371 , 118.8281, 28.2568 , 118.4766, 28.3008 , 118.4766, 28.3447 , 118.3887, 28.7842 , 118.0371, 29.0479 , 118.0371, 29.1797 , 118.2129, 29.3994
                      
                      ]
              )},
              material: Cesium.Color.fromCssColorString('rgba(6,25,47,.6)')
          }
      })
  }
//统一导出该模块，包含方法和所需变量
export default comjs;
